package com.training.java.core.collections.one;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;


public class SetDemo {
	
public static void main(String[] args) {
	Set<String> students = new HashSet<String>();//Use HashSet if you care about the speed. It is the quickest.
	//List list = new LinkedList(); 
	
	
	students.add("Sam");
	students.add("Almas");
	students.add("Almas");// linked list and array list also accepts duplicates
	students.add("Vinod");
	students.add("Henry");
	
	//Car focus = new Car("Ford", "Focus", 2014);
	//list.add(focus); // String and objects are not compatible types and therefore
	//will throw an error when system will try to print after Henry
	
	
	//Read from list
	Iterator<String> ite = students.iterator();
	
	while(ite.hasNext()) // read until hasNext value is true
	{
		String studentName = ite.next();
		System.out.println("Student name = " + studentName);
	}
	
	System.out.println("*********************");
	//Read the same list using for each loop
	for(String studentName : students)
	{
		System.out.println("Student name = " + studentName);
	}
}
}
